﻿<UserControl x:Class="BizControl.Presentation.PersonEditModule.Views.PersonEditView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:res="clr-namespace:BizControl.Presentation.Infrastructure.Properties;assembly=BizControl.Presentation.Infrastructure"
             xmlns:csla="clr-namespace:Csla.Xaml;assembly=Csla.Xaml"
             xmlns:controls="clr-namespace:BizControl.Presentation.Infrastructure.Controls;assembly=BizControl.Presentation.Infrastructure"
             xmlns:starRatingCtl="clr-namespace:BizControl.Presentation.Infrastructure.Controls.StarRating;assembly=BizControl.Presentation.Infrastructure"
             Name="PersonEditViewControl">

    <StackPanel>
        <ToolBar>
            <Button x:Name="SaveButton" HorizontalAlignment="Left" 
                    VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                    Width="25" Height="25" ToolTip="Сохранить"
                    IsEnabled="{Binding CanSave}"
                    Template="{StaticResource OkButtonTemplate}">
            </Button>
            <csla:TriggerAction TargetControl="{Binding ElementName=SaveButton}" MethodName="Save"/>
            <Button HorizontalAlignment="Right" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
                    Width="25" Height="25" ToolTip="Закрыть"
                    Command="{Binding Path=CloseCommand}"
                    Template="{StaticResource CancelButtonTemplate}">
            </Button>
        </ToolBar>
        <TabControl Margin="2,2,8,8"
                    HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
                    ItemContainerStyle="{StaticResource CustomTabItemStyle}">
            <TabItem>
                <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                    <StackPanel>
                        <Grid Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="200" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" HorizontalAlignment="Left">
                                <Border Margin="2" BorderThickness="1" BorderBrush="WhiteSmoke">
                                    <Image Width="150" Height="150" Source="{Binding Path=Model.Photo, Converter={StaticResource ImageConverter}}" />
                                </Border>
                                <TextBlock HorizontalAlignment="Center">
                                    <Hyperlink Command="{Binding LoadPhotoCommand}">
                                        <TextBlock Text="Загрузить фото..." />
                                    </Hyperlink>
                                </TextBlock>
                                <Border Margin="0,5,0,5" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />
                                <TextBlock Text="Рейтинг пользователя:" VerticalAlignment="Center" />
                                <StackPanel Orientation="Horizontal">
                                    <starRatingCtl:StarRatingControl x:Name="ratingCtl" Value="2.5" NumberOfStars="3"
                                                                     Minimum="0" Maximum="3" Step="0.1"
                                                                     IsEnabled="False"
                                                                     BackgroundColor="Transparent"
                                                                     StarForegroundColor="Yellow"
                                                                     StarOutlineColor="Black"
                                                                     VerticalAlignment="Center"
                                                                     VerticalContentAlignment="Center" />

                                    <TextBlock Text="83 %" ToolTip="2.5 / 3.0" Margin="2" FontWeight="Bold" VerticalAlignment="Center" />
                                    <Border Margin="0,5,0,5" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />
                                </StackPanel>
                            </StackPanel>

                            <Grid Grid.Column="1" Margin="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="160" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Column="0" Grid.Row="0" Text="Фамилия:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBox VerticalContentAlignment="Center" Width="150" Margin="2" FontWeight="Bold" 
                                             Text="{Binding Path=Model.LastName, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=LastName}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="1" Text="Имя:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBox VerticalContentAlignment="Center" Width="150" Margin="2" FontWeight="Bold" 
                                             Text="{Binding Path=Model.FirstName, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=FirstName}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="1" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="2" Text="Отчество:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBox VerticalContentAlignment="Center" Width="150" Margin="2" FontWeight="Bold" 
                                             Text="{Binding Path=Model.MiddleName, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=MiddleName}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="2" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="3" Text="Электронная почта:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBox VerticalContentAlignment="Center" Width="150" Margin="2" FontWeight="Bold" 
                                             Text="{Binding Path=Model.Email, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=Email}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="3" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="4" Text="Комментарий:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Left">
                                    <TextBox VerticalContentAlignment="Top" Width="250" Height="150" AcceptsReturn="True" TextWrapping="Wrap"
                                             ScrollViewer.VerticalScrollBarVisibility="Auto"
                                             Margin="2" Text="{Binding Path=Model.Comment, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=Comment}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="4" BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="5" Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}"
                                           Text="Логин:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Left"
                                            Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}">
                                    <TextBox VerticalContentAlignment="Top" Width="250" Margin="2" 
                                             Text="{Binding Path=Model.Login, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=Login}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="5" Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}"
                                        BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                                <TextBlock Grid.Column="0" Grid.Row="6" Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}"
                                           Text="Пароль:" VerticalAlignment="Center" />
                                <StackPanel Grid.Column="1" Grid.Row="6" Orientation="Horizontal" HorizontalAlignment="Left"
                                            Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}">
                                    <TextBox VerticalContentAlignment="Top" Width="250" Margin="2" 
                                             Text="{Binding Path=Model.PasswordHash, UpdateSourceTrigger=PropertyChanged}" />
                                    <csla:PropertyStatus Margin="2" DataContext="{Binding Model}" Property="{Binding Path=PasswordHash}"/>
                                </StackPanel>
                                <Border Grid.Column="0" Grid.Row="6" Visibility="{Binding Path=Model.IsNew, Converter={StaticResource BoolToVisibilityConverter}}"
                                        BorderThickness="0,0,0,1" BorderBrush="{StaticResource BorderLightBrush}" />

                            </Grid>
                        </Grid>
                        <controls:PersonMarkControl Margin="5"
                                                    Visibility="{Binding ElementName=PersonEditViewControl, Path=DataContext.Model.HasMarks, Converter={StaticResource BoolToVisibilityConverter}}"
                                                    DataContext="{Binding Path=Model.Marks}" />
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </StackPanel>
</UserControl>
